let ele = document.querySelectorAll('.username')[0];
let password = document.getElementsByClassName('password')[0];
let pwd = document.getElementsByClassName('re-password')[0];
let btn = document.querySelector('#btn');

let flag1 = false
let flag2 = false
let flag3 = false
ele.onblur = checkUsername;
function checkUsername(e) {
    let value = e.target.value
    let reg = /^[0-9a-zA-Z_-]{4,16}$/;
    if(reg.test(value)){
        flag1 = true
    }else{
        flag1 = false
        alert('用户名输入错误')
    }
    checkBtn()
}
password.onblur = checkPassword;
function checkPassword(e) {
    let value = e.target.value
    let reg = /^[0-9a-zA-Z_-]{8,15}$/;
    if(reg.test(value)){
        flag2 = true
    }else{
        flag2 = false
        alert('密码输入错误')
    }
    checkPwd()
    checkBtn()
}
pwd.onblur = checkPwd;
function checkPwd(){
    let PwdValue = pwd.value;
    let PasswordValue = password.value;
    if(PwdValue === PasswordValue) {
        flag3 = true
    } else if(PwdValue !== PasswordValue && PwdValue != ''){
        flag3 = false
        alert('输入的密码不一致')
    }
    checkBtn()
}
btn.onclick = function(){
    alert('success');
}
function checkBtn(){
    if(flag1 && flag2 && flag3){
        btn.disabled = false;
    }else{
        btn.disabled = true;
    }
}